package com.example.xinai.Util;

public class UserContext {

    // 分别存储用户名和用户id
    private static final ThreadLocal<String> currentTelephone = new ThreadLocal<>();
    private static final ThreadLocal<Integer> currentUserId = new ThreadLocal<>();

    // 设置当前用户名
    public static void setCurrentUser(String telephone) {
        currentTelephone.set(telephone);
    }

    // 获取当前用户名
    public static String getCurrentUser() {
        return currentTelephone.get();
    }

    // 设置当前用户id
    public static void setCurrentId(int id) {
        currentUserId.set(id);
    }

    // 获取当前用户id
    public static Integer getCurrentId() {
        return currentUserId.get();
    }

    // 清除
    public static void clear() {
        currentTelephone.remove();
        currentUserId.remove();
    }}
